package cn.crsc.openlookeng.handler;

import org.apache.commons.lang3.StringUtils;
import org.springframework.util.PropertyPlaceholderHelper;

import java.util.Properties;

public class PropertyPlaceHolderUtil {
    private static final String placeholderPrefix = "#{";
    private static final String placeholderSuffix = "}";

    private static final PropertyPlaceholderHelper helper = new PropertyPlaceholderHelper(placeholderPrefix, placeholderSuffix);

    private PropertyPlaceHolderUtil() {
    }

    public static final String replace(String text, Properties props) {
        if (StringUtils.isBlank(text) || props == null || props.isEmpty()) {
            return text;
        }

        return helper.replacePlaceholders(text, props);
    }

}